﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit;

namespace YArchitech.HVAC
{
	public partial class FormTotalMarkSetting : HYBaseForm
	{
		public FormTotalMarkSetting(ShowMarkType showType)
		{
			this.InitializeComponent();
			this.userSetting = new UserSetting();
			this.commonFont = this.userSetting.GetFontSetting();
			this.diameterMark = this.userSetting.GetDiameterMarkSetting();
			this.slopeMark = this.userSetting.GetSlopeMarkSetting();
			this.pipeOffset = this.userSetting.GetOffsetMarkSetting();
			this.ductMark = this.userSetting.GetDuctMarkSetting();
			this.terminalMark = this.userSetting.GetTerminalMarkSetting();
			this.synthesizeMark = this.userSetting.GetTubeSynthesize();
			this.quickMark = this.userSetting.GetQuickPositionType();
			this.markType = showType;
			this.InitialAllInfo();
		}

		private void FormTotalMarkSetting_Load(object sender, EventArgs e)
		{
			this.isLoad = false;
		}

		private void InitialAllInfo()
		{
			this.InitialAllComboxSource();
			this.InitialAllTextBoxDefaultValue();
			this.InitialAllRadioButton();
			this.InitialAllCheckBox();
			this.SetTabAndGroupEnable();
		}

		public void SetTabAndGroupEnable()
		{
			List<GroupBox> allGroupBox = this.GetAllGroupBox();
			if (this.markType == ShowMarkType.Font || this.markType == ShowMarkType.Synthesize || this.markType == ShowMarkType.QuickMark)
			{
				this.tabControl1.SelectedTab = this.tbgCommon;
			}
			else if (this.markType == ShowMarkType.Duct || this.markType == ShowMarkType.Terminal)
			{
				this.tabControl1.SelectedTab = this.tbgDuct;
			}
			else if (this.markType == ShowMarkType.Slope || this.markType == ShowMarkType.Offset || this.markType == ShowMarkType.Diameter)
			{
				this.tabControl1.SelectedTab = this.tbgPipe;
			}
			this.SetGroupBoxsEnable(this.GetSpecialProfession(this.markType), allGroupBox);
			if (this.markType == ShowMarkType.Diameter)
			{
				this.SetDiameterEnabled();
			}
			if (this.markType == ShowMarkType.Duct)
			{
				this.hyCmbDuctOffsetPrefix.SelectedItem = this.ductPrefixValue;
			}
		}

		private List<GroupBox> GetAllGroupBox()
		{
			List<GroupBox> list = new List<GroupBox>();
			foreach (object obj in this.tabControl1.Controls)
			{
				TabPage tabPage = ((System.Windows.Forms.Control)obj) as TabPage;
				if (tabPage != null)
				{
					foreach (object obj2 in tabPage.Controls)
					{
						GroupBox groupBox = ((System.Windows.Forms.Control)obj2) as GroupBox;
						if (groupBox != null)
						{
							list.Add(groupBox);
						}
					}
				}
			}
			return list;
		}

		private void SetGroupBoxsEnable(List<string> listGrpName, List<GroupBox> listGrp)
		{
			foreach (GroupBox groupBox in listGrp)
			{
				if (listGrpName == null || listGrpName.Count < 1)
				{
					groupBox.Enabled = true;
				}
				else if (listGrpName.Contains(groupBox.Name))
				{
					groupBox.Enabled = true;
				}
				else
				{
					groupBox.Enabled = false;
				}
			}
		}

		private List<string> GetSpecialProfession(ShowMarkType showType)
		{
			List<string> list = new List<string>();
			switch (showType)
			{
			case ShowMarkType.Font:
				list.Add(this.hyGrpFontSet.Name);
				break;
			case ShowMarkType.Duct:
				list.Add(this.hyGrpDuctOffset.Name);
				list.Add(this.hyGrpDuctSize.Name);
				list.Add(this.hyGrpDuctSplit.Name);
				break;
			case ShowMarkType.Terminal:
				list.Add(this.hyGrpTerminal.Name);
				break;
			case ShowMarkType.Diameter:
				list.Add(this.hyGrpDiameterOffsetSplit.Name);
				list.Add(this.hyGrpPipeDiameter.Name);
				list.Add(this.hyGrpPipeOffset.Name);
				break;
			case ShowMarkType.Offset:
				list.Add(this.hyGrpPipeOffset.Name);
				break;
			case ShowMarkType.Slope:
				list.Add(this.hyGrpPipeSlope.Name);
				break;
			case ShowMarkType.Synthesize:
				list.Add(this.hyGrpTubeSynthesize.Name);
				break;
			case ShowMarkType.QuickMark:
				list.Add(this.hyGrpQuickPosition.Name);
				break;
			}
			return list;
		}

		public string GetMarkAccuracy()
		{
			return this.hyCmbPresice.SelectedItem.ToString();
		}

		private void InitialAllComboxSource()
		{
			this.InitialCombox(this.hyCmbFont, this.GetSpecComboBoxSources(this.hyCmbFont.Name), this.commonFont.Font);
			this.InitialCombox(this.hyCmbPresice, this.GetSpecComboBoxSources(this.hyCmbPresice.Name), this.commonFont.Presice);
			this.InitialCombox(this.hyCmbAlign, this.GetSpecComboBoxSources(this.hyCmbAlign.Name), this.commonFont.Align);
			this.InitialCombox(this.hyCmbSlopeStyle, this.GetSpecComboBoxSources(this.hyCmbSlopeStyle.Name), this.slopeMark.SlopeStyle);
			this.InitialCombox(this.hyCmbMarkSlopeStyle, this.GetSpecComboBoxSources(this.hyCmbMarkSlopeStyle.Name), this.slopeMark.Style);
			this.InitialCombox(this.hyCmbPipeOffsetPrefix, StringTools.GetSplitedString('$', this.pipeOffset.PrefixSource), this.pipeOffset.Prefix);
			this.InitialCombox(this.hyCmbPipeConnectStr, this.GetSpecComboBoxSources(this.hyCmbPipeConnectStr.Name), this.diameterMark.Splite);
			this.InitialCombox(this.hyCmbDuctSuffix, this.GetSpecComboBoxSources(this.hyCmbDuctSuffix.Name), this.ductMark.DuctSuffix);
			this.InitialCombox(this.hyCmbRoundDuctPrefix, this.GetSpecComboBoxSources(this.hyCmbRoundDuctPrefix.Name), this.ductMark.DuctPrefix);
			this.InitialCombox(this.hyCmbDuctSizeSplit, this.GetSpecComboBoxSources(this.hyCmbDuctSizeSplit.Name), this.ductMark.Splite);
			this.InitialCombox(this.hyCmbTerminalSplite, this.GetSpecComboBoxSources(this.hyCmbTerminalSplite.Name), this.terminalMark.Splite);
			this.InitialCombox(this.hyCmbDuctOffsetPrefix, StringTools.GetSplitedString('$', this.ductMark.PrefixSource), this.ductMark.OffsetPrefix);
			this.InitialCombox(this.hyCmbPipeSuffixUnit, this.GetSpecComboBoxSources(this.hyCmbPipeSuffixUnit.Name), this.pipeOffset.Suffix);
			this.InitialCombox(this.hyCmbDuctSuffixUnit, this.GetSpecComboBoxSources(this.hyCmbDuctSuffixUnit.Name), this.ductMark.OffsetSuffix);
			this.InitialCombox(this.hyCmbPipeUnitVisible, this.GetSpecComboBoxSources(this.hyCmbPipeUnitVisible.Name), this.pipeOffset.UnitVisible);
			this.InitialCombox(this.hyCmbUnitVisible, this.GetSpecComboBoxSources(this.hyCmbUnitVisible.Name), this.ductMark.UnitVisible);
			this.InitialCombox(this.hyCmbPipeSizeSplitStr, this.GetSpecComboBoxSources(this.hyCmbPipeSizeSplitStr.Name), this.pipeOffset.Splite);
		}

		private void InitialAllTextBoxDefaultValue()
		{
			this.InitialTextBox(this.hyTxtDistanceLead, this.commonFont.LeadDistance.ToString());
			this.InitialTextBox(this.hyTxtDistancePipe, this.commonFont.TubeDistance.ToString());
			this.InitialTextBox(this.hyTxtLeadRotia, this.commonFont.LeadRotia.ToString());
			this.InitialTextBox(this.hyTxtWHRotia, this.commonFont.FontGWRotia.ToString());
			this.InitialTextBox(this.hyTxtFontHeight, this.commonFont.FontHeight.ToString());
			this.InitialTextBox(this.hyTxtMinPipeDiameter, this.diameterMark.TubeDiameter.ToString());
			this.InitialTextBox(this.hyTxtMinPipeLength, this.diameterMark.TubeLength.ToString());
			this.InitialTextBox(this.hyTxtMinDuctLength, this.ductMark.TubeLength.ToString());
		}

		private void InitialAllRadioButton()
		{
			if (this.synthesizeMark.Pipe)
			{
				this.InitialSynthesizePipe(this.rdoPipeCenter);
			}
			else
			{
				this.InitialSynthesizePipe(this.rdoPipeOutside);
			}
			if (this.synthesizeMark.Duct)
			{
				this.InitialSynthesizeDuct(this.rdoDuctCenter);
			}
			else
			{
				this.InitialSynthesizeDuct(this.rdoDuctOutside);
			}
			if (this.synthesizeMark.CableTray)
			{
				this.InitialSynthesizeCableTray(this.rdoCableTrayCenter);
			}
			else
			{
				this.InitialSynthesizeCableTray(this.rdoCableTrayOutside);
			}
			if (this.synthesizeMark.Conduit)
			{
				this.InitialSynthesizeConduit(this.rdoConduitCenter);
			}
			else
			{
				this.InitialSynthesizeConduit(this.rdoConduitOutside);
			}
			if (this.synthesizeMark.BeOffset)
			{
				this.InitialSynthesize(this.rdoSynthesizeOffset);
			}
			else
			{
				this.InitialSynthesize(this.rdoSynthesizeVertical);
			}
			switch (this.quickMark)
			{
			case QuickPosition.QuickType.Proximity:
				this.InitialQuickPosition(this.rdoProximity);
				break;
			case QuickPosition.QuickType.Wall:
				this.InitialQuickPosition(this.rdoWall);
				break;
			case QuickPosition.QuickType.Grid:
				this.InitialQuickPosition(this.rdoGrid);
				break;
			default:
				this.InitialQuickPosition(this.rdoProximity);
				break;
			}
			if (this.pipeOffset.Content.Equals(this.rdoPipeOffset.Text))
			{
				this.InitialPipeOffset(this.rdoPipeOffset);
				this.label18.Enabled = true;
				this.hyCmbPipeOffsetPrefix.Enabled = true;
			}
			else
			{
				this.InitialPipeOffset(this.rdoPipeObselute);
				this.label18.Enabled = false;
				this.hyCmbPipeOffsetPrefix.Enabled = false;
			}
			if (this.ductMark.MarkContent.Equals(this.rdoDuctOffset.Text))
			{
				this.InitialDuctOffset(this.rdoDuctOffset);
				this.label24.Enabled = true;
				this.hyCmbDuctOffsetPrefix.Enabled = true;
				return;
			}
			this.InitialDuctOffset(this.rdoDuctObsolute);
			this.label24.Enabled = false;
			this.hyCmbDuctOffsetPrefix.Enabled = false;
		}

		private void InitialAllCheckBox()
		{
			this.InitialCheckBox(this.ckbPipeSystemType, this.diameterMark.GetBoolValue(this.diameterMark.SystemType, false));
			this.InitialCheckBox(this.ckbPipeThickness, this.diameterMark.GetBoolValue(this.diameterMark.Thickness, false));
			this.InitialCheckBox(this.ckbDrawSlash, this.diameterMark.GetBoolValue(this.diameterMark.DrawSlash, true));
			this.InitialCheckBox(this.ckbPipeOffset, this.diameterMark.GetBoolValue(this.diameterMark.PipeOffset, false));
			this.InitialCheckBox(this.ckbCrossWallTowSides, this.diameterMark.GetBoolValue(this.diameterMark.TwoSides, false));
			this.InitialCheckBox(this.ckbHaveTransition, this.diameterMark.GetBoolValue(this.diameterMark.Reduce, false));
			this.InitialCheckBox(this.ckbDrawLineBox, this.terminalMark.GetBoolValue(this.terminalMark.DrawLineBox, true));
			this.SetPipeMarkStatue();
		}

		public void SetPipeDiameterShowState()
		{
			if (this.markType == ShowMarkType.Diameter)
			{
				if (this.ckbPipeOffset.Checked && !this.ckbPipeThickness.Checked)
				{
					this.hyGrpPipeOffset.Enabled = true;
					this.hyGrpDiameterOffsetSplit.Enabled = true;
					return;
				}
				this.hyGrpPipeOffset.Enabled = false;
				this.hyGrpDiameterOffsetSplit.Enabled = false;
			}
		}

		private void InitialSynthesizePipe(RadioButton rdoButton)
		{
			this.rdoPipeCenter.Checked = false;
			this.rdoPipeOutside.Checked = false;
			rdoButton.Checked = true;
		}

		private void InitialSynthesizeDuct(RadioButton rdoButton)
		{
			this.rdoDuctCenter.Checked = false;
			this.rdoDuctOutside.Checked = false;
			rdoButton.Checked = true;
		}

		private void InitialSynthesizeCableTray(RadioButton rdoButton)
		{
			this.rdoCableTrayCenter.Checked = false;
			this.rdoCableTrayOutside.Checked = false;
			rdoButton.Checked = true;
		}

		private void InitialSynthesizeConduit(RadioButton rdoButton)
		{
			this.rdoConduitCenter.Checked = false;
			this.rdoConduitOutside.Checked = false;
			rdoButton.Checked = true;
		}

		private void InitialSynthesize(RadioButton rdoButton)
		{
			this.rdoSynthesizeOffset.Checked = false;
			this.rdoSynthesizeVertical.Checked = false;
			rdoButton.Checked = true;
		}

		private void InitialQuickPosition(RadioButton rdoButton)
		{
			this.rdoWall.Checked = false;
			this.rdoProximity.Checked = false;
			this.rdoGrid.Checked = false;
			rdoButton.Checked = true;
		}

		private void InitialPipeOffset(RadioButton rdoButton)
		{
			this.rdoPipeObselute.Checked = false;
			this.rdoPipeOffset.Checked = false;
			rdoButton.Checked = true;
		}

		private void InitialDuctOffset(RadioButton rdoButton)
		{
			this.rdoDuctObsolute.Checked = false;
			this.rdoDuctOffset.Checked = false;
			rdoButton.Checked = true;
		}

		private List<string> GetSpecComboBoxSources(string controlName)
		{
			List<string> list = new List<string>();
			switch ((FormTotalMarkSetting.ControlsName)Enum.Parse(typeof(FormTotalMarkSetting.ControlsName), controlName))
			{
			case FormTotalMarkSetting.ControlsName.hyCmbFont:
				list = StringTools.GetWindowsFontNames();
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbPresice:
				list.Add("0.000");
				list.Add("0.00");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbAlign:
				list.Add("始端对齐");
				list.Add("中心对齐");
				list.Add("末端对齐");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbSlopeStyle:
				list.Add("0.001");
				list.Add("%");
				if (RevitVersion.Version != "2019")
				{
					list.Add("‰");
				}
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbMarkSlopeStyle:
				list.Add("全箭头");
				list.Add("半箭头");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbPipeSuffixUnit:
			case FormTotalMarkSetting.ControlsName.hyCmbDuctSuffixUnit:
				list.Add("m");
				list.Add("mm");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbPipeUnitVisible:
			case FormTotalMarkSetting.ControlsName.hyCmbUnitVisible:
				list.Add("不显示");
				list.Add("显示");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbPipeOffsetPrefix:
				list.Add("H");
				list.Add("h");
				list.Add("F");
				list.Add("f");
				list.Add("A");
				list.Add("a");
				list.Add("无");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbPipeConnectStr:
				list.Add("X");
				list.Add("·");
				list.Add("空格");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbDuctSuffix:
				list.Add("无");
				list.Add("mm");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbRoundDuctPrefix:
				list.Add("Ф");
				list.Add("D");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbDuctSizeSplit:
				list.Add(",");
				list.Add("空格");
				list.Add("（）");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbTerminalSplite:
				list.Add("空格");
				list.Add("，");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbDuctOffsetPrefix:
				list.Add("底");
				list.Add("中");
				list.Add("顶");
				list.Add("无");
				list.Add("H");
				list.Add("h");
				list.Add("F");
				list.Add("f");
				list.Add("A");
				list.Add("a");
				break;
			case FormTotalMarkSetting.ControlsName.hyCmbPipeSizeSplitStr:
				list.Add(",");
				list.Add("空格");
				list.Add("（）");
				break;
			}
			return list;
		}

		private void InitialCombox(System.Windows.Forms.ComboBox cmbBox, List<string> sourceList, string selectedValue)
		{
			if (cmbBox == null || sourceList == null || sourceList.Count < 1)
			{
				return;
			}
			int selectedIndex = 0;
			for (int i = 0; i < sourceList.Count; i++)
			{
				cmbBox.Items.Add(sourceList[i]);
				if (!string.IsNullOrEmpty(selectedValue) && sourceList[i].Equals(selectedValue))
				{
					selectedIndex = i;
				}
			}
			cmbBox.SelectedIndex = selectedIndex;
		}

		private void InitialTextBox(System.Windows.Forms.TextBox txtBox, string txtValue)
		{
			txtBox.Text = txtValue;
		}

		private void InitialCheckBox(CheckBox ckBox, bool beCheck)
		{
			ckBox.Checked = beCheck;
		}

		private void FormTotalMarkSetting_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.SaveAllInterfaceInfo();
		}

		private void cmbRoundDuctPrefix_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (!this.isLoad)
			{
				YJKMessageBox.Information("“圆风管前缀”和“后缀”的设置，在Reivt功能区“管理-MEP设置-机械设置”里面的“圆形风管尺寸前缀”中完成！");
			}
		}

		private void cmbRoundDuctSuffix_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private void ckbDrawLineBox_CheckedChanged(object sender, EventArgs e)
		{
			if (this.ckbDrawLineBox.Checked)
			{
				this.hyCmbTerminalSplite.Enabled = false;
				return;
			}
			this.hyCmbTerminalSplite.Enabled = true;
		}

		private void ckbPipeSystemType_CheckedChanged(object sender, EventArgs e)
		{
			this.SetPipeMarkStatue();
		}

		private void SetPipeMarkStatue()
		{
			if (this.ckbPipeSystemType.Checked || this.ckbPipeOffset.Checked)
			{
				this.ckbPipeThickness.Checked = false;
				this.ckbPipeThickness.Enabled = false;
			}
			else
			{
				this.ckbPipeThickness.Enabled = true;
				this.hyGrpDiameterOffsetSplit.Enabled = false;
			}
			if (this.ckbPipeThickness.Checked)
			{
				this.ckbPipeSystemType.Checked = false;
				this.ckbPipeOffset.Checked = false;
				this.ckbPipeSystemType.Enabled = false;
				this.ckbPipeOffset.Enabled = false;
				this.hyCmbPipeConnectStr.Enabled = true;
				this.hyGrpDiameterOffsetSplit.Enabled = false;
				this.hyGrpPipeOffset.Enabled = false;
			}
			else
			{
				this.ckbPipeSystemType.Enabled = true;
				this.ckbPipeOffset.Enabled = true;
				this.hyGrpDiameterOffsetSplit.Enabled = true;
				this.hyGrpPipeOffset.Enabled = true;
				this.hyCmbPipeConnectStr.Enabled = false;
			}
			if (this.ckbPipeOffset.Checked)
			{
				this.hyGrpDiameterOffsetSplit.Enabled = true;
				this.hyGrpPipeOffset.Enabled = true;
				return;
			}
			this.hyGrpDiameterOffsetSplit.Enabled = false;
			this.hyGrpPipeOffset.Enabled = false;
		}

		private string GetStrValueByBool(bool beTrue)
		{
			if (!beTrue)
			{
				return "false";
			}
			return "true";
		}

		private double GetDoubleValue(string strValue)
		{
			double result;
			try
			{
				if (string.IsNullOrEmpty(strValue))
				{
					result = 0.0;
				}
				else
				{
					result = Convert.ToDouble(strValue);
				}
			}
			catch (Exception)
			{
				result = 0.0;
			}
			return result;
		}

		private void SaveFontSetting()
		{
			this.commonFont = new CommonFont();
			this.commonFont.Font = this.hyCmbFont.SelectedItem.ToString();
			this.commonFont.FontHeight = this.GetDoubleValue(this.hyTxtFontHeight.Text);
			this.commonFont.FontGWRotia = this.GetDoubleValue(this.hyTxtWHRotia.Text);
			this.commonFont.Align = this.hyCmbAlign.SelectedItem.ToString();
			this.commonFont.LeadRotia = this.GetDoubleValue(this.hyTxtLeadRotia.Text);
			this.commonFont.Presice = this.hyCmbPresice.SelectedItem.ToString();
			this.commonFont.LeadDistance = this.GetDoubleValue(this.hyTxtDistanceLead.Text);
			this.commonFont.TubeDistance = this.GetDoubleValue(this.hyTxtDistancePipe.Text);
			this.userSetting.WriteFontSetting(this.commonFont);
		}

		private void SaveDuctMarkSetting()
		{
			if (this.rdoDuctObsolute.Checked)
			{
				this.ductMark.MarkContent = this.rdoDuctObsolute.Text;
			}
			else
			{
				this.ductMark.MarkContent = this.rdoDuctOffset.Text;
			}
			this.ductMark.DuctPrefix = this.hyCmbRoundDuctPrefix.Text.ToString();
			this.ductMark.DuctSuffix = this.hyCmbDuctSuffix.Text.ToString();
			this.ductMark.Splite = this.hyCmbDuctSizeSplit.Text.ToString();
			this.ductMark.OffsetPrefix = this.hyCmbDuctOffsetPrefix.Text.ToString();
			this.ductMark.OffsetSuffix = this.hyCmbDuctSuffixUnit.Text.ToString();
			this.ductMark.TubeLength = this.GetDoubleValue(this.hyTxtMinDuctLength.Text);
			this.ductMark.UnitVisible = this.hyCmbUnitVisible.Text.ToString();
			this.userSetting.WriteDuctMarkSetting(this.ductMark);
		}

		private void SaveTeminalMarkSetting()
		{
			this.terminalMark = new TerminalMarkSet();
			this.terminalMark.DrawLineBox = this.GetStrValueByBool(this.ckbDrawLineBox.Checked);
			this.terminalMark.Splite = this.hyCmbTerminalSplite.SelectedItem.ToString();
			this.userSetting.WriteTerminalMarkSetting(this.terminalMark);
		}

		private void SaveDiameterMarkSetting()
		{
			this.diameterMark = new PipeDiameterMarkSet();
			this.diameterMark.SystemType = this.GetStrValueByBool(this.ckbPipeSystemType.Checked);
			this.diameterMark.Thickness = this.GetStrValueByBool(this.ckbPipeThickness.Checked);
			this.diameterMark.Splite = this.hyCmbPipeConnectStr.SelectedItem.ToString();
			this.diameterMark.PipeOffset = this.GetStrValueByBool(this.ckbPipeOffset.Checked);
			this.diameterMark.DrawSlash = this.GetStrValueByBool(this.ckbDrawSlash.Checked);
			this.diameterMark.TwoSides = this.GetStrValueByBool(this.ckbCrossWallTowSides.Checked);
			this.diameterMark.Reduce = this.GetStrValueByBool(this.ckbHaveTransition.Checked);
			this.diameterMark.TubeLength = this.GetDoubleValue(this.hyTxtMinPipeLength.Text);
			this.diameterMark.TubeDiameter = this.GetDoubleValue(this.hyTxtMinPipeDiameter.Text);
			this.diameterMark.Diameter = "50";
			this.userSetting.WriteDiameterMarkSetting(this.diameterMark);
		}

		private void SaveOffsetMarkSetting()
		{
			if (this.rdoPipeObselute.Checked)
			{
				this.pipeOffset.Content = this.rdoPipeObselute.Text;
			}
			else
			{
				this.pipeOffset.Content = this.rdoPipeOffset.Text;
			}
			this.pipeOffset.Prefix = this.hyCmbPipeOffsetPrefix.Text.ToString();
			this.pipeOffset.Splite = this.hyCmbPipeSizeSplitStr.Text.ToString();
			this.pipeOffset.Suffix = this.hyCmbPipeSuffixUnit.Text.ToString();
			this.pipeOffset.UnitVisible = this.hyCmbPipeUnitVisible.Text.ToString();
			this.userSetting.WriteOffsetMarkSetting(this.pipeOffset);
		}

		private void SaveSlopeMarkSetting()
		{
			this.slopeMark = new SlopeMarkSet();
			this.slopeMark.SlopeStyle = this.hyCmbSlopeStyle.SelectedItem.ToString();
			this.slopeMark.Style = this.hyCmbMarkSlopeStyle.SelectedItem.ToString();
			this.userSetting.WriteSlopeMarkSetting(this.slopeMark);
		}

		private void SaveSynthesizeMarkSetting()
		{
			this.synthesizeMark = new TubeSynthesize();
			this.synthesizeMark.BeOffset = this.rdoSynthesizeOffset.Checked;
			this.synthesizeMark.CableTray = this.rdoCableTrayCenter.Checked;
			this.synthesizeMark.Conduit = this.rdoConduitCenter.Checked;
			this.synthesizeMark.Duct = this.rdoDuctCenter.Checked;
			this.synthesizeMark.Pipe = this.rdoPipeCenter.Checked;
			this.userSetting.WriteTubeSynthesize(this.synthesizeMark);
		}

		private void SaveQuickPositionSetting()
		{
			if (this.rdoGrid.Checked)
			{
				this.userSetting.WriteQuickPositionType(QuickPosition.QuickType.Grid);
				return;
			}
			if (this.rdoWall.Checked)
			{
				this.userSetting.WriteQuickPositionType(QuickPosition.QuickType.Wall);
				return;
			}
			this.userSetting.WriteQuickPositionType(QuickPosition.QuickType.Proximity);
		}

		private void SaveAllInterfaceInfo()
		{
			this.userSetting = new UserSetting();
			if (this.beSave)
			{
				this.SaveFontSetting();
				this.SaveDuctMarkSetting();
				this.SaveTeminalMarkSetting();
				this.SaveDiameterMarkSetting();
				this.SaveOffsetMarkSetting();
				this.SaveSlopeMarkSetting();
				this.SaveSynthesizeMarkSetting();
				this.SaveQuickPositionSetting();
			}
		}

		private string GetDefaultValue(System.Windows.Forms.TextBox tb)
		{
			string empty = string.Empty;
			if (tb == null)
			{
				return empty;
			}
			string name = tb.Name;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 1241266721u)
			{
				if (num <= 781619558u)
				{
					if (num != 760952157u)
					{
						if (num == 781619558u)
						{
							if (name == "hyTxtMinDuctLength")
							{
								empty = this.oldOtherMiniLength;
							}
						}
					}
					else if (name == "hyTxtMinPipeDiameter")
					{
						empty = this.oldTxtMiniDiameter;
					}
				}
				else if (num != 1201848914u)
				{
					if (num == 1241266721u)
					{
						if (name == "hyTxtDistancePipe")
						{
							empty = this.oldDistancPipe;
						}
					}
				}
				else if (name == "hyTxtMinPipeLength")
				{
					empty = this.oldTxtMiniLength;
				}
			}
			else if (num <= 3062441867u)
			{
				if (num != 2929087607u)
				{
					if (num == 3062441867u)
					{
						if (name == "hyTxtLeadRotia")
						{
							empty = this.oldLeadRotia;
						}
					}
				}
				else if (name == "hyTxtDistanceLead")
				{
					empty = this.oldDistanceLead;
				}
			}
			else if (num != 3525622848u)
			{
				if (num == 3963003848u)
				{
					if (name == "hyTxtFontHeight")
					{
						empty = this.oldFontHeight;
					}
				}
			}
			else if (name == "hyTxtWHRotia")
			{
				empty = this.oldFontWHRotia;
			}
			return empty;
		}

		private void hyTxt_KeyPress(object sender, KeyPressEventArgs e)
		{
			if ((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == '.' || e.KeyChar == '\b')
			{
				e.Handled = false;
				return;
			}
			e.Handled = true;
		}

		private void hyTxt_Leave(object sender, EventArgs e)
		{
			Regex regex = new Regex("^[.]+[\\d]*$");
			System.Windows.Forms.TextBox textBox = (System.Windows.Forms.TextBox)sender;
			string text = ((System.Windows.Forms.TextBox)sender).Text;
			this.TrimInvalidPreffix(ref text, '0');
			this.TrimInvalidSuffix(ref text, '.');
			double num;
			bool flag = double.TryParse(text, out num);
			if (string.IsNullOrEmpty(text) || regex.IsMatch(text) || !flag)
			{
				textBox.Text = this.GetDefaultValue(textBox);
				return;
			}
			textBox.Text = text;
		}

		private void TrimInvalidPreffix(ref string input, char preffix)
		{
			if (string.IsNullOrEmpty(input))
			{
				return;
			}
			if (input.IndexOf(preffix) == 0 && (input.IndexOf('.') == -1 || input.IndexOf('.') > 1))
			{
				input = input.Substring(1, input.Length - 1);
				if (string.IsNullOrEmpty(input))
				{
					return;
				}
				this.TrimInvalidPreffix(ref input, preffix);
			}
		}

		private void TrimInvalidSuffix(ref string input, char suffix)
		{
			if (string.IsNullOrEmpty(input))
			{
				return;
			}
			if (input.LastIndexOf(suffix) == input.Length - 1)
			{
				input = input.TrimEnd(new char[]
				{
					suffix
				});
			}
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			this.beSave = true;
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.beSave = false;
			base.DialogResult = DialogResult.No;
		}

		private void btnPrefix_Click(object sender, EventArgs e)
		{
			new FormPrefixSetting().ShowDialog();
		}

		public void SetPipeSlopeEnabled(bool beEnableed)
		{
			this.hyCmbSlopeStyle.Enabled = !beEnableed;
		}

		public void SetDrawSlidIsEnabled(bool isEnabled)
		{
			this.isDrawSlidEnabled = isEnabled;
		}

		public void SetDiameterOtherEnabled(bool isEnabled)
		{
			this.isDiameterOtherEnabled = isEnabled;
		}

		public void SetDuctMarkPrefixSelectedItem(string prefixText)
		{
			this.ductPrefixValue = prefixText;
			this.hyCmbDuctOffsetPrefix.SelectedItem = this.ductPrefixValue;
		}

		public string GetDuctPrefixText()
		{
			return this.hyCmbDuctOffsetPrefix.Text;
		}

		public void SetDiameterEnabled()
		{
			this.ckbDrawSlash.Enabled = this.isDrawSlidEnabled;
			this.ckbCrossWallTowSides.Enabled = this.isDiameterOtherEnabled;
			this.ckbHaveTransition.Enabled = this.isDiameterOtherEnabled;
			this.label17.Enabled = this.isDiameterOtherEnabled;
			this.hyTxtMinPipeLength.Enabled = this.isDiameterOtherEnabled;
			this.label18.Enabled = this.isDiameterOtherEnabled;
			this.hyTxtMinPipeDiameter.Enabled = this.isDiameterOtherEnabled;
			if (this.rdoPipeOffset.Checked)
			{
				this.hyGrpDiameterOffsetSplit.Enabled = true;
			}
			this.hyCmbPipeConnectStr.Enabled = this.ckbPipeThickness.Checked;
		}

		public void SetDrawSlashEnable(bool beEnable)
		{
			this.ckbDrawSlash.Enabled = beEnable;
		}

		private void hyCmbPipeOffsetPrefix_TextChanged(object sender, EventArgs e)
		{
			System.Windows.Forms.ComboBox comboBox = sender as System.Windows.Forms.ComboBox;
			if (comboBox == null)
			{
				return;
			}
			string text = comboBox.Text;
			if (comboBox.Name == "hyCmbPipeOffsetPrefix" && !this.pipeOffset.PrefixSource.Contains(text))
			{
				this.pipeOffset.PrefixSource = text + "$" + this.pipeOffset.PrefixSource;
			}
			if (comboBox.Name == "hyCmbDuctOffsetPrefix" && !this.ductMark.PrefixSource.Contains(text))
			{
				this.ductMark.PrefixSource = text + "$" + this.ductMark.PrefixSource;
			}
		}

		private void rdoPipeOffset_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoPipeOffset.Checked)
			{
				this.label18.Enabled = true;
				this.hyCmbPipeOffsetPrefix.Enabled = true;
				return;
			}
			this.label18.Enabled = false;
			this.hyCmbPipeOffsetPrefix.Enabled = false;
		}

		private void rdoPipeObselute_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoPipeObselute.Checked)
			{
				this.label18.Enabled = false;
				this.hyCmbPipeOffsetPrefix.Enabled = false;
				return;
			}
			this.label18.Enabled = true;
			this.hyCmbPipeOffsetPrefix.Enabled = true;
		}

		private void rdoDuctOffset_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoDuctOffset.Checked)
			{
				this.label24.Enabled = true;
				this.hyCmbDuctOffsetPrefix.Enabled = true;
				return;
			}
			this.label24.Enabled = false;
			this.hyCmbDuctOffsetPrefix.Enabled = false;
		}

		private void rdoDuctObsolute_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoDuctObsolute.Checked)
			{
				this.label24.Enabled = false;
				this.hyCmbDuctOffsetPrefix.Enabled = false;
				return;
			}
			this.label24.Enabled = true;
			this.hyCmbDuctOffsetPrefix.Enabled = true;
		}

		private void hyCmbPipeSuffixUnit_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private UserSetting userSetting;

		private CommonFont commonFont;

		private PipeDiameterMarkSet diameterMark;

		private SlopeMarkSet slopeMark;

		private PipeOffsetMarkSet pipeOffset;

		private DuctMarkSet ductMark;

		private TerminalMarkSet terminalMark;

		private TubeSynthesize synthesizeMark;

		private QuickPosition.QuickType quickMark = QuickPosition.QuickType.Grid;

		private ShowMarkType markType = ShowMarkType.InValid;

		private bool isLoad = true;

		private bool beSave = true;

		private bool isDrawSlidEnabled;

		private bool isDiameterOtherEnabled;

		public bool beEnableSlope = true;

		private string ductPrefixValue = "";

		private string oldFontHeight = string.Empty;

		private string oldFontWHRotia = string.Empty;

		private string oldLeadRotia = string.Empty;

		private string oldDistanceLead = string.Empty;

		private string oldDistancPipe = string.Empty;

		private string oldOtherMiniLength = string.Empty;

		private string oldTxtMiniLength = string.Empty;

		private string oldTxtMiniDiameter = string.Empty;

		private enum ControlsName
		{
			hyCmbFont,
			hyCmbPresice,
			hyCmbAlign,
			hyCmbSlopeStyle,
			hyCmbMarkSlopeStyle,
			hyCmbPipeSuffixUnit,
			hyCmbPipeUnitVisible,
			hyCmbPipeOffsetPrefix,
			hyCmbPipeConnectStr,
			hyCmbDuctSuffix,
			hyCmbRoundDuctPrefix,
			hyCmbDuctSizeSplit,
			hyCmbTerminalSplite,
			hyCmbDuctOffsetPrefix,
			hyCmbDuctSuffixUnit,
			hyCmbUnitVisible,
			hyCmbPipeSizeSplitStr
		}
	}
}
